package com.xianshiyue;

import com.scienjus.smartqq.client.SmartQQClient;
import com.scienjus.smartqq.model.Group;

import java.util.List;
import java.util.Random;

/**
 * Project  : smartqq
 * Author   : Wu Tian Qiang
 * Date     : 2016/7/15
 */
public class SendMessageThread implements Runnable {

    private SmartQQClient client;
    private List<Group> monitorGroups;
    private Random random = new Random();


    private String[] messages = {
            "http://weibo.com/xianshiyue \n微博名：闲适悦网\n互粉，未回粉的请私信。\n",
            "http://weibo.com/xianshiyue",
            "http://weibo.com/xianshiyue 诚信互粉诚信互粉诚信互粉",
            "诚信互粉 http://weibo.com/xianshiyue",
            "闲适悦网   http://weibo.com/xianshiyue",
            "http://weibo.com/xianshiyue 闲适悦网",
            "http://weibo.com/xianshiyue 微博名：闲适悦网",
            "http://weibo.com/xianshiyue 粉粉粉",
            "粉粉粉 http://weibo.com/xianshiyue ",
            "求粉，必回 http://weibo.com/xianshiyue ",
            "互粉必回 http://weibo.com/xianshiyue",
            "互粉走起 http://weibo.com/xianshiyue",
            "http://weibo.com/xianshiyue 互粉",
            "http://weibo.com/xianshiyue (｡･∀･)ﾉﾞ嗨起来 互粉",
            "互粉 http://weibo.com/xianshiyue 互粉",
            "互粉 http://weibo.com/xianshiyue",
            "微博名：闲适悦网 http://weibo.com/xianshiyue 互粉",
            "微博名：闲适悦网 http://weibo.com/xianshiyue 互粉走起！",
            "http://weibo.com/xianshiyue 互粉走起！",
            "http://weibo.com/xianshiyue 未回粉的请私信",
            "http://weibo.com/xianshiyue 么么哒！",
            "http://weibo.com/xianshiyue 互粉啦 么么哒！",
    };

    public SendMessageThread(SmartQQClient client, List<Group> monitorGroups) {
        this.client = client;
        this.monitorGroups = monitorGroups;
    }

    @Override
    public void run() {
        while (true) {
            try {
                int min = 0;
                int max = messages.length;
                int index = random.nextInt(max) % (max - min + 1) + min;
                for (Group group : monitorGroups) {
                    client.sendMessageToGroup(group.getId(), messages[index]);
                    Thread.sleep(1000 * 15);
                }
                Thread.sleep(1000 * 60 * 3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}
